
#!/bin/bash
# keypress.sh: Detect a user keypress ("hot keys").
old_tty_settings=$(stty -g)   # Save old settings (why?).
stty -icanon time 10
trap 'echo Exit.. && stty "$old_tty_settings" && exit' 2 15
xtemp=$(head -c1) 
echo
echo $xtemp
                              # on non-GNU systems
x=1
xr(){
    temp=$(dd bs=1 count=1 2> /dev/null)          # or $(dd bs=1 count=1 2> /dev/null)
    if [ $temp ]
    then
        x=$temp
    fi
    echo timeout...
}
while [ 1 ]
do
    xr
    echo $x
done
# Thanks, Stephane Chazelas.

exit 0


